package com.example.ioc.controller;


import com.example.ioc.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Service;

@Controller
public class UserController {
    //属性注入
    //@Autowired
    //private UserService userService;

    //构造方法注入，只有一个构造方法，@Autowred可省略，如果有多个构造方法需要加上注解
 /*   public UserController() {
    }

    @Autowired
    public UserController(UserService userService) {
        this.userService = userService;
    }
*/
    //setter方法注入
    private UserService userService;

    //不可省略
    @Autowired
    public void setUserService(UserService userService) {
        this.userService = userService;
    }

    public void sayhi(){
        System.out.println("hi,Controller");
        userService.sayhi();
    }
}
